<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="admin/css/pintuer.css">
<link rel="stylesheet" href="admin/css/admin.css">
<link rel="stylesheet" href="admin/css/city-picker.css">
<script src="admin/js/jquery.js"></script>
<script src="admin/js/pintuer.js"></script>
<script src="admin/js/city-picker.data.js"></script>
<script src="admin/js/city-picker.js"></script>
<script src="ckeditor/ckeditor.js"></script>
<script src="ckfinder/ckfinder.js"></script>
<script src="ckeditor/samples/js/sample.js" type="text/javascript"></script>
<link href="ckeditor/samples/sample.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script>
$(function(){
	$('#add_member_form').bind('submit',function(){
		var formData = new FormData();
		var title = $('input[name="title_5"]').val();
		var content = CKEDITOR.instances.TextArea1.getData();
		var fmResource = $('input[name="fmResource_5"]').val();
		var id = $('input[name="id_5"]').val();
		var prov_city = $('#city-picker3').val();
		var validate_prov_city = $('input[name="isneturldesc"]').val();
		formData.append('title',title);
		formData.append('content',content);
		if(prov_city != '')
			fmResource = prov_city+"/"+fmResource.substring(fmResource.lastIndexOf("/")+1);
		formData.append('fmResource',fmResource);
		if(id != '0'){
			formData.append('id',id);
		}
		$.ajax({
			url:'admin/addServerPoint.do',
			type:'post',
			data:formData,
			dataType:'html',
			cache: false,  
	        contentType: false,  
	        processData: false,
			success:function(strValue){
				if(strValue.length > 0){
					alert(strValue);
					clearData();
					window.location.href="admin/serverpoint.do";
				}
			}
		});
		return false;
		
});
});
	function del(id){
		if(confirm("确定删除id为"+id+"的服务网点？")){
			$.ajax({url:'admin/delSPById.do?id='+id,context: document.body,success:function(data){
				alert(data);
				window.location.reload();
			}})
		}
	}
	function fillcontext(id,title,resource,fmResource,isneturlDesc,count){
		$('#addorupdate').html('修改网点');
		$('input[name="id_5"]').attr('value',id);
		$('input[name="title_5"]').attr('value',title);
		$('input[name="fmResource_5"]').attr('value',fmResource);
		var content = $('#contentdiv'+count).html();
    	CKEDITOR.instances.TextArea1.setData(content);
		$('#showhead').attr('src',resource);
		$('input[name="isneturldesc"]').attr('value',isneturlDesc);
	}
	function clearData(){
		document.getElementById('top').scrollIntoView();
		$('#addorupdate').html('新增网点');
		$('input[name="id_5"]').attr('value','');
		$('input[name="title_5"]').val('');
		$('input[name="fmResource_5"]').attr('value','');
		CKEDITOR.instances.TextArea1.setData('');
		$('#showhead').attr('src','');
		$('input[name="isneturldesc"]').attr('value','');
	}
</script>
<div class="panel admin-panel" id="top">
	<div class="padding border-bottom">  
  	<button type="button" class="button border-yellow" onclick="document.getElementById('addMember').scrollIntoView();"><span class="icon-plus-square-o"></span> 添加网点</button>
  	</div>
  <div class="panel-head"><strong class="icon-reorder"> 网点列表</strong></div>
  <table class="table table-hover text-center">
    <tr>
      <th width="5%">ID</th>
      <th width="10%">网点名</th>
      <th width="15%">具体地址</th>
      <th width="20%">网点描述</th>
      <th width="10%">所属城市</th>
      <th width="15%">操作</th>
    </tr>
   	<c:if test="${!empty list }">
   		<c:forEach items="${list }" var="list" varStatus="a">
   			<tr>
      			<td>${list.id }</td>     
      			<td>${list.title }</td>
      			<td>${list.fmResource }</td>     
      			<td>
      				<div id="contentdiv${a.count }" style="display: none;">${list.content }</div>
      				<c:if test="${fn:contains(list.content,'<img') }">
      					图文内容，点击修改查看详情
      				</c:if>
      				<c:if test="${!fn:contains(list.content,'<img') }">
      					${list.content }
      				</c:if>
      			</td>
      			<td>${list.isneturlDesc }</td>
      			<td><div class="button-group">
      			<a class="button border-main" href="javascript:void(0);" onclick="fillcontext('${list.id}','${list.title }','${list.resource }','${list.fmResource}','${list.fmResourceDesc }','${a.count }')"><span class="icon-edit"></span> 修改</a>
      			<a class="button border-red" href="javascript:void(0)" onclick="del('${list.id}')"><span class="icon-trash-o"></span> 删除</a>
      			</div></td>
    		</tr>
   		</c:forEach>
   	</c:if>
  </table>
</div>
<div class="panel admin-panel margin-top" id="addMember" style="font-size: 14px;">
  <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> <cite id="addorupdate">增加网点</cite></strong></div>
  <div class="body-content">
    <form method="post" id="add_member_form" class="form-x" enctype="multipart/form-data">   
      <input type="hidden" name="id_5"  value="0" /> 
      <div class="form-group">
      
      <div class="form-group">
        <div class="label">
          <label>网点名：</label>
        </div>
        <div class="field">
          <input type="text" class="input w30" name="title_5" value="" data-validate="required:请输入名称" width="30" />         
          <div class="tips"></div>
        </div>
      </div> 
      <div class="form-group">
      	<div class="label">
      		<label>所属城市：</label>
      	</div>
      	<div class="field">
            <input type="hidden" value="" name="isneturldesc"/>
            <div class="docs-methods">
                <div id="distpicker">
                    <div class="form-group">
                        <div style="position: relative;">
                            <input id="city-picker3" class="input w30" type="text" value="北京市/北京市/丰台区" data-toggle="city-picker">
                        </div>
                    </div>
                </div>
        </div>
          </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>具体地址：</label>
        </div>
        <div class="field">
          <input type="text" class="input w30" name="fmResource_5" value="" data-validate="required:请输入地址" width="30" />         
          <div class="tips"></div>
        </div>
      </div> 
        <div class="label">
          <label>网点描述：</label>
        </div>
        <div class="field">
          <textarea class="ckeditor" name="content" id="TextArea1" cols="20" rows="2"></textarea>
          <script type="text/javascript">
          	CKEDITOR.replace('TextArea1');
          </script>  
        </div>
      </div>
     <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <input type="submit" class="button bg-main icon-check-square-o" value="提交"/>
        </div>
      </div>
    </form>
  </div>
 </div>
</body></html>